package cn.aion.dao;

import cn.aion.model.AnchorChannel;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 *
 * Created by 虚空之翼 on 2016/11/24.
 */
public interface AnchorChannelDAO {
    @Insert("insert into ad_anchor_channel (name,header,detail,youku_url,create_time,update_time,status) " +
            "values (#{data.name},#{data.header},#{data.detail},#{data.youkuUrl},unix_timestamp(now()),unix_timestamp(now()),1)")
    @Options(useGeneratedKeys = true, keyProperty = "data.id")
    int save(@Param("data") AnchorChannel data);

    @Select("select * from ad_anchor_channel where id=#{id}")
    AnchorChannel selectOne(@Param("id") int id);

    @Select("select * from ad_anchor_channel where name=#{name} limit 1")
    AnchorChannel selectOneByName(@Param("name") String name);

    @Select("select * from ad_anchor_channel limit #{start},#{end}")
    List<AnchorChannel> selectAll(@Param("start") int start, @Param("end") int end);

    @Update("update ad_anchor_channel set header=#{data.header},play_total=#{data.playTotal},fans_total=#{data.fansTotal}," +
            "detail=#{data.detail},channel=#{data.channel},channel_rank=#{data.channelRank},site_rank=#{data.siteRank},update_time=unix_timestamp(now()) where id=#{data.id}")
    int update(@Param("data") AnchorChannel data);
    @Update("update ad_anchor_channel set youku_play=#{play},youku_fans=#{fans},video_total=#{videos},update_time=unix_timestamp(now()) where id=#{id}")
    int updateYoukuTotal(@Param("id") int id, @Param("play") Long play, @Param("fans") int fans, @Param("videos") int videos);

    @Update("update ad_anchor_channel set iqiyi_name=name,iqiyi_url=#{url},is_search=1 where id=#{id}")
    int updateIqiyiUrl(@Param("url") String url, @Param("id") int id);
    @Update("update ad_anchor_channel set iqiyi_play=#{play},iqiyi_fans=#{fans} where id=#{id}")
    int updateIqiyiTotal(@Param("id") int id, @Param("play") Long play, @Param("fans") int fans);

    @Update("update ad_anchor_channel set sohu_name=name,sohu_url=#{url},is_search=1 where id=#{id}")
    int updateSohuUrl(@Param("url") String url, @Param("id") int id);
    @Update("update ad_anchor_channel set sohu_play=#{play} where id=#{id}")
    int updateSohuPlay(@Param("id") int id, @Param("play") Long play);
    @Update("update ad_anchor_channel set sohu_fans=#{fans} where id=#{id}")
    int updateSohuFans(@Param("id") int id, @Param("fans") int fans);

    @Update("update ad_anchor_channel set qq_name=name,qq_url=#{url},is_search=1 where id=#{id}")
    int updateQQUrl(@Param("url") String url, @Param("id") int id);
    @Update("update ad_anchor_channel set qq_play=#{play},qq_fans=#{fans} where id=#{id}")
    int updateQQTotal(@Param("id") int id, @Param("play") Long play, @Param("fans") int fans);

    @Update("update ad_anchor_channel set bilibili_name=name,bilibili_url=#{url},is_search=1 where id=#{id}")
    int updateBilibiliUrl(@Param("url") String url, @Param("id") int id);
    @Update("update ad_anchor_channel set bilibili_play=#{play},bilibili_fans=#{fans} where id=#{id}")
    int updateBilibiliTotal(@Param("id") int id, @Param("play") Long play, @Param("fans") int fans);

    @Update("update ad_anchor_channel set " +
            "play_total=youku_play+iqiyi_play+qq_play+sohu_play+bilibili_play," +
            "fans_total=youku_fans+iqiyi_fans+qq_fans+sohu_fans+bilibili_fans " +
            "where id=#{id}")
    int updateTotal(@Param("id") int id);
}
